/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.univcasa.managing.impl;

import com.univcasa.db.model.CompteEtudiant;
import com.univcasa.db.model.ComptePersonnel;
import com.univcasa.managing.LdapDBManager;
import com.univcasa.managing.StudentLoginManager;
import java.util.List;

/**
 *
 * @author issam
 */
public class LoginManagerImpl implements StudentLoginManager {


    private LdapDBManager ldapManager;


    public LoginManagerImpl(LdapDBManager ldapManager) {
        this.ldapManager = ldapManager;
    }

    public String getAvailablelogin(CompteEtudiant etudiant) {

        String uidPattern = etudiant.getUidPattern("*") ;
        String uid = etudiant.getUidPattern("").replace("*", ".") ;
        List uids = ldapManager.recupererListeUids( uidPattern   ) ;

        if ( ! uids.contains( uid ) ){
            etudiant.setUid( uid );
        } else if ( ! uids.contains( uid.replace(".", "-") )) {
            etudiant.setUid( uid.replace(".", "-")  );
        } else if (! uids.contains( uid.replace(".", "_") ) ){
            etudiant.setUid( uid.replace(".", "_")  );
        }
        else if (! uids.contains( etudiant.getUidPattern(".").replace("*", ".") ) ){
            etudiant.setUid( etudiant.getUidPattern(".").replace("*", ".")   );
        } else if (! uids.contains( etudiant.getUidPattern(".").replace("*", "-") ) ){
            etudiant.setUid( etudiant.getUidPattern(".").replace("*", "-")   );
        } else if (! uids.contains( etudiant.getUidPattern(".").replace("*", "_") ) ){
            etudiant.setUid( etudiant.getUidPattern(".").replace("*", "_")   );
        }
        else if (! uids.contains( etudiant.getUidPattern("-").replace("*", ".") ) ){
            etudiant.setUid( etudiant.getUidPattern("-").replace("*", ".")   );
        } else if (! uids.contains( etudiant.getUidPattern("-").replace("*", "-") ) ){
            etudiant.setUid( etudiant.getUidPattern("-").replace("*", "-")   );
        } else if (! uids.contains( etudiant.getUidPattern("-").replace("*", "_") ) ){
            etudiant.setUid( etudiant.getUidPattern("-").replace("*", "_")   );
        }
        else if (! uids.contains( etudiant.getUidPattern("_").replace("*", ".") ) ){
            etudiant.setUid( etudiant.getUidPattern("_").replace("*", ".")   );
        } else if (! uids.contains( etudiant.getUidPattern("_").replace("*", "-") ) ){
            etudiant.setUid( etudiant.getUidPattern("_").replace("*", "-")   );
        } else if (! uids.contains( etudiant.getUidPattern("_").replace("*", "_") ) ){
            etudiant.setUid( etudiant.getUidPattern("_").replace("*", "_")   );
        }
  
        return etudiant.getUid();

    }

    public String getPersAvailablelogin(ComptePersonnel pers) {
        
        return "" ;
    }

}
